<?php 
/**
 * 活动静态类
 */
class Activity{
	/**
	 * 报名申请话费补贴
	 * @param <int> $uin
	 */
	static public function addDraw($uin){
		$Db = loadDB();
		
		$time = time();
		//把数据写入数组
		$insert_date = array(
			'uin'=>$uin,
			'id'=>$time,
			'state'=>0,
			'time'=>$time,
			'stale'=>0,
		);
		$success = $Db->doInsert('draw' , $insert_date);
		
		return $success ? 0 : 511;
	}
	/**
	 * 查询报名情况是否已过期
	 * @param <int> $uin
	 */
	static public function getDraw($uin){
		$Db=loadDB();
		
		$list = $Db->getOne("SELECT  * FROM `draw` WHERE draw.uin={$uin} and draw.stale=0");
		return $list;
	}
	/**
	 * 查询个人报名总数
	 * @param <int> $uin
	 */
	static public function getOneCount($uin){
		$Db = loadDB();
		
		$result= $Db->getOne("SELECT COUNT(*) AS `count` FROM `draw` WHERE draw.uin={$uin}");

		return empty($result) ? 0 : $result['count'];
	}
	/**
	 * 查询中奖总数
	 */
	static public function getLotteryCount(){
		$Db = loadDB();
		
		$result= $Db->getOne("SELECT COUNT(*) AS `count` FROM `draw` WHERE draw.state=1");

		return empty($result) ? 0 : $result['count'];
	}
	/**
	 * 查询个人报名情况
	 * @param <int> $uin
	 * @param <int> $pageSize
	 * @param <int> $pageCount
	 */
	static public function getAllDraw($uin,$pageSize, $pageCount){
		$Db=loadDB();
		
		$pageSize=($pageSize-1)*$pageCount;
		$list = $Db->getAll("SELECT  * FROM `draw` WHERE draw.uin={$uin} ORDER BY id DESC LIMIT {$pageSize} , {$pageCount}");
		
		return $list;
	}
	/**
	 * 查询中奖情况
	 * @param <int> $uin
	 * @param <int> $pageSize
	 * @param <int> $pageCount
	 */
	static public function getAllLottery($uin,$pageSize, $pageCount){
		$Db=loadDB();
		
		$pageSize=($pageSize-1)*$pageCount;
		$list = $Db->getAll("SELECT `time` , `mobile` , `name` , `sex` , `proving` FROM `draw`,`user_baseinfo` WHERE draw.state=1 AND draw.uin=user_baseinfo.uin ORDER BY id DESC LIMIT {$pageSize} , {$pageCount}");
		
		return $list;
	}
	/**
	 * 查询抽奖总数
	 */
	static public function getCount(){
		$Db = loadDB();
		
		$result= $Db->getOne("SELECT COUNT(*) AS `count` FROM `draw` WHERE draw.state=0");

		return empty($result) ? 0 : $result['count'];
	}
	/**
	 * 查询抽奖情况
	 * @param <int> $pageSize
	 * @param <int> $pageCount
	 */
	static public function getAll($pageSize, $pageCount){
		$Db=loadDB();
		
		$pageSize=($pageSize-1)*$pageCount;
		$list = $Db->getAll("SELECT `time` , draw.uin , `mobile` , `name` , `sex` , `proving` FROM `draw`,`user_baseinfo` WHERE draw.state=0 AND draw.uin=user_baseinfo.uin ORDER BY id DESC LIMIT {$pageSize} , {$pageCount}");
		
		return $list;
	}
	/**
	 * 随机抽奖
	 */
	static public function getRandAll(){
		$Db=loadDB();
		
		$list = $Db->getAll("SELECT `time` , draw.uin , `mobile` , `name` , `sex` , `proving` FROM `draw`,`user_baseinfo` WHERE draw.state=0 AND draw.uin=user_baseinfo.uin ORDER BY RAND() DESC LIMIT 30");
		
		return $list;
	}
	/**
	 * 批量查询信息
	 */
	static public function getAllDrawAc($id){
		$Db=loadDB();
//		print_r($id);
		$list = $Db->getAll("SELECT * FROM `draw` WHERE draw.state=0 AND id IN ($id)");
		
		return $list;
	}
	/**
	 * 选中中奖
	 */
	static public function getUpdate($id){
		$Db=loadDB();
	
		$success =$Db->query("UPDATE draw SET state=1,stale=1 WHERE id IN ({$id})");
		return $success ? 0 : 521;
	}
	/**
	 * 删除抽奖用户
	 */
	static public function getDelete($id){
		$Db=loadDB();
		
		$success =$Db->query("DELETE FROM `draw` WHERE `id` IN ({$id})");
		
		return $success ? 0 : 522;
	}
}
# end of script